package com.itboy.mall.sms.skufullreduction.controller;

import java.util.List;
import java.util.Arrays;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itboy.mall.sms.skufullreduction.domain.MallSkuFullReduction;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.sms.skufullreduction.vo.MallSkuFullReductionVo;
import com.itboy.mall.sms.skufullreduction.bo.MallSkuFullReductionQueryBo;
import com.itboy.mall.sms.skufullreduction.bo.MallSkuFullReductionAddBo;
import com.itboy.mall.sms.skufullreduction.bo.MallSkuFullReductionEditBo;
import com.itboy.mall.sms.skufullreduction.service.IMallSkuFullReductionService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商品满减信息Controller
 *
 * @author itboy
 * @date 2021-08-08
 */
@Validated
@Api(value = "商品满减信息控制器", tags = {"商品满减信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/skuFullReduction")
public class MallSkuFullReductionController extends BaseController {

    private final IMallSkuFullReductionService iMallSkuFullReductionService;

    /**
     * 查询商品满减信息列表
     */
    @ApiOperation("查询商品满减信息列表")
    @PreAuthorize("@ss.hasPermi('mall:skuFullReduction:list')")
    @GetMapping("/list")
    public TableDataInfo<MallSkuFullReductionVo> list(@Validated MallSkuFullReductionQueryBo bo) {
        return iMallSkuFullReductionService.queryPageList(bo);
    }

    /**
     * 导出商品满减信息列表
     */
    @ApiOperation("导出商品满减信息列表")
    @PreAuthorize("@ss.hasPermi('mall:skuFullReduction:export')")
    @Log(title = "商品满减信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallSkuFullReductionVo> export(@Validated MallSkuFullReductionQueryBo bo) {
        List<MallSkuFullReductionVo> list = iMallSkuFullReductionService.queryList(bo);
        ExcelUtil<MallSkuFullReductionVo> util = new ExcelUtil<MallSkuFullReductionVo>(MallSkuFullReductionVo.class);
        return util.exportExcel(list, "商品满减信息");
    }

    /**
     * 获取商品满减信息详细信息
     */
    @ApiOperation("获取商品满减信息详细信息")
    @PreAuthorize("@ss.hasPermi('mall:skuFullReduction:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallSkuFullReductionVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallSkuFullReductionService.queryById(id));
    }

	/**
	 * 按skuId获取商品满减信息详细信息
	 */
	@ApiOperation("按skuId获取商品满减信息详细信息")
	@GetMapping("/querySkuFullReductionBySkuId/{skuId}")
	public AjaxResult<MallSkuFullReduction> querySkuFullReductionBySkuId(@NotNull(message = "skuId不能为空")
													  @PathVariable("skuId") Long skuId) {
		return AjaxResult.success(iMallSkuFullReductionService.getOne(new LambdaQueryWrapper<MallSkuFullReduction>().eq(MallSkuFullReduction::getSkuId,skuId)));
	}

    /**
     * 新增商品满减信息
     */
    @ApiOperation("新增商品满减信息")
    @PreAuthorize("@ss.hasPermi('mall:skuFullReduction:add')")
    @Log(title = "商品满减信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallSkuFullReductionAddBo bo) {
        return toAjax(iMallSkuFullReductionService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改商品满减信息
     */
    @ApiOperation("修改商品满减信息")
    @PreAuthorize("@ss.hasPermi('mall:skuFullReduction:edit')")
    @Log(title = "商品满减信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallSkuFullReductionEditBo bo) {
        return toAjax(iMallSkuFullReductionService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除商品满减信息
     */
    @ApiOperation("删除商品满减信息")
    @PreAuthorize("@ss.hasPermi('mall:skuFullReduction:remove')")
    @Log(title = "商品满减信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallSkuFullReductionService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
